package sw6.visualschedule.extendedViews;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 *	A ScrollView that can be disabled
 */
public class DisableableScrollView extends ScrollView {

    private transient Boolean mAllowedToScroll = true;

    /**
     * Tells if scrollview is currently scrollable
     * @return true if scrollview is scrollable
     */
    public Boolean getAllowedToScroll() {
        return mAllowedToScroll;
    }

    /**
     * Defines whether scrollview can be scrolled
     * @param true if scrollview should be scrollable
     */
    public void setAllowedToScroll(final Boolean allowedToScroll) {
        mAllowedToScroll = allowedToScroll;
    }

    /**
     * Creates a disableable scrollview
     * @param context	application context
     * @param attrs	see super
     */
    public DisableableScrollView(final Context context, final AttributeSet attrs) {
        super(context, attrs);
        setFadingEdgeLength(0);
    }
    
    /*
    @Override
    public boolean onTouchEvent(final MotionEvent event) {
        return super.onTouchEvent(event);
    }
    */
    
    /**
     * intercepts motionevents if allowed to scroll.
     * 
     * @return true if intercepted (will normally be true when scrollable), false if scroll is disabled.    
     */
    @Override
    public boolean onInterceptTouchEvent(final MotionEvent event) {
        boolean result = false;
        
    	if (mAllowedToScroll) {
    		result = super.onInterceptTouchEvent(event);
    	}
    	
    	return result;
    }
}